<?
include('Crypt/Blowfish/MCrypt.php');

/** 暗号化を行う **/
function my_encrypt ($string, $key) {
  if($string==""){ return $string;}
  srand((double) microtime() * 1000000);
  $key = md5($key);
  $bf =& Crypt_Blowfish::factory('cbc', null, null, CRYPT_BLOWFISH_PHP);
  if (PEAR::isError($bf)) {
    echo $bf->getMessage();
    exit;
  }
  $iv = 'abc123+=';
  $bf->setKey($key, $iv);
  return base64_encode($bf->encrypt($string));

}

/** 復号化を行う **/
function my_decrypt($string, $key) {
  if($string==""){ return $string;}
  $string = base64_decode($string);
  $key = md5($key);
  $iv = 'abc123+=';
  $bf =& Crypt_Blowfish::factory('cbc', null, null, CRYPT_BLOWFISH_PHP);
  if (PEAR::isError($bf)) {
      echo $bf->getMessage();
      exit;
  }
  $iv = 'abc123+=';
  $bf->setKey($key, $iv);
  return rtrim($bf->decrypt($string),"\0");
}
?>
